CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(u2daemon)

FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(CURL)
FIND_PACKAGE(LibXml2)

IF(OPENSSL_FOUND)
	INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
ELSE(OPENSSL_FOUND)
	MESSAGE(FATAL_ERROR "openssl not found")
ENDIF(OPENSSL_FOUND)

IF(ZLIB_FOUND)
    INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
ELSE(ZLIB_FOUND)
    MESSAGE(FATAL_ERROR "zlib not found")
ENDIF(ZLIB_FOUND)

IF(CURL_FOUND)
    INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
ELSE(CURL_FOUND)
    MESSAGE(FATAL_ERROR "curl not found")
ENDIF(CURL_FOUND)

IF(LIBXML2_FOUND)
    INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
ELSE(LIBXML2_FOUND)
    MESSAGE(FATAL_ERROR "libxml2 not found")
ENDIF(LIBXML2_FOUND)

EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
IF(GCC_VERSION VERSION_LESS 4.6)
	MESSAGE(FATAL_ERROR "gcc version ${GCC_VERSION} must >= 4.6")
ENDIF()

SET(CMAKE_BUILD_TYPE "Debug")
IF(RELEASE_MODE)
	SET(CMAKE_BUILD_TYPE "Release")
	ADD_DEFINITIONS(-DNDEBUG)
ELSE(RELEASE_MODE)
	ADD_DEFINITIONS(-DDEBUG)
ENDIF()

ADD_DEFINITIONS(-std=c++0x)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../lib)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})

ADD_SUBDIRECTORY(u2daemon)
